package logic

import (
	"common/model"
	"context"
	"errors"
	product "product_server/proto"
)

func (p *ProductServer) BargainProductInfo(ctx context.Context, req *product.BargainProductInfoRequest) (*product.BargainProductInfoResponse, error) {
	bargain, err := model.GetBargainProductInfo(req.Id)
	if err != nil {
		return nil, errors.New("砍价商品不存在")
	}

	info, err := model.GetProductInfo(bargain.ProductId)
	if err != nil {
		return nil, errors.New("商品不存在")
	}

	return &product.BargainProductInfoResponse{
		Id:            bargain.Id,
		ProductId:     bargain.ProductId,
		StoreName:     info.StoreName,
		Image:         info.Image,
		Sales:         info.Sales,
		OriginalPrice: bargain.OriginalPrice,
		MinPrice:      bargain.MinPrice,
		TotalCuts:     bargain.TotalCuts,
		StartTime:     bargain.StartTime.Format("2006-01-02 15:04:05"),
		EndTime:       bargain.EndTime.Format("2006-01-02 15:04:05"),
		BargainStock:  bargain.Stock,
	}, nil

}
